import java.util.*;

public class Solution {

    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }

    }
    public TreeNode createTree() {
        TreeNode A = new TreeNode(10);
//        TreeNode B = new TreeNode(6);
//        TreeNode C = new TreeNode(14);
//        TreeNode D = new TreeNode(4);
//        TreeNode E = new TreeNode(8);
//        TreeNode F = new TreeNode(12);
//        TreeNode G = new TreeNode(16);
//        //TreeNode H = new TreeNode('H');
//
//        A.left = B;
//        A.right = C;
//        B.left = D;
//        B.right = E;
//        C.left = F;
//        C.right = G;
        return A;//就是根节点
    }

    public TreeNode head = null;
    public TreeNode Convert(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        Stack<TreeNode> stack = new Stack<>();
        TreeNode cur = root;
        while(cur != null || !stack.empty()){
            while(cur != null){
                stack.push(cur);
                cur = cur.left;
            }
            cur = stack.peek();
            stack.pop();
            queue.offer(cur);
            cur = cur.right;
        }

        while(!queue.isEmpty()){
            if(cur == null){
                head = queue.poll();
                if(queue.isEmpty()){
                    cur = head;
                }else {
                    cur = queue.poll();
                    head.right = cur;
                    cur.left = head;
                }
            }else{
                TreeNode tmp = queue.poll();
                cur.right = tmp;
                tmp.left = cur;
                cur = tmp;
            }
        }
        return head;
    }

    //宝石与石头
    public int numJewelsInStones(String jewels, String stones) {
        int count = 0;
        HashSet<Character> set = new HashSet<>();
        for(char ch : jewels.toCharArray()){
            set.add(ch);
        }
        for(char ch : stones.toCharArray()){
            if(set.contains(ch)){
                count++;
            }
        }
        return count;
    }
//    public int numJewelsInStones(String jewels, String stones) {
//        HashSet<Character> set = new HashSet<>();
//        int count = 0;
//        for(int i = 0;i < jewels.length(); i++){
//            char ch = jewels.charAt(i);
//            set.add(ch);
//        }
//        for(int i = 0;i < stones.length(); i++){
//            char ch = stones.charAt(i);
//            if(set.contains(ch)){
//                count++;
//            }
//        }
//        return count;
//    }

    //只出现一次的数字
    public int singleNumber(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for(int i : nums){
            if(!set.contains(i)){
                set.add(i);
            }else{
                set.remove(i);
            }
        }
        for(int i : nums){
            if(set.contains(i)){
                return i;
            }
        }
        return -1;
    }
//    public int singleNumber(int[] nums) {
//        HashSet<Integer> set = new HashSet<>();
//        for(int i = 0; i < nums.length; i++){
//            if(!set.contains(nums[i])){
//                set.add(nums[i]);
//            }else{
//                set.remove(nums[i]);
//            }
//        }
//        for(int i = 0;i < nums.length; i++){
//            if(set.contains(nums[i])){
//                return (nums[i]);
//            }
//        }
//        return -1;
//    }

    //坏键盘打字
    // 注意类名必须为 Main, 不要有任何 package xxx 信息
    public class Main {
        public static void main(String[] args) {
            HashSet<Character> set1 = new HashSet<>();
            HashSet<Character> set2 = new HashSet<>();
            Scanner in = new Scanner(System.in);
            // 注意 hasNext 和 hasNextLine 的区别
            while (in.hasNextLine()) { // 注意 while 处理多个 case
                String a = in.nextLine();
                String b = in.nextLine();
                //func(a, b);
                for (char ch : b.toUpperCase().toCharArray()) {
                    set1.add(ch);
                }
                for (char ch : a.toUpperCase().toCharArray()) {
                    if (!set1.contains(ch) && !set2.contains(ch)) {
                        System.out.print(ch);
                        set2.add(ch);
                    }
                }
            }
        }
        // public static void func(String a, String b) {
        //     HashSet<Character> set1 = new HashSet<>();
        //     HashSet<Character> set2 = new HashSet<>();
        //     for (char ch : b.toUpperCase().toCharArray()) {
        //         set1.add(ch);
        //     }
        //     for (char ch : a.toUpperCase().toCharArray()) {
        //         if (!set1.contains(ch) && !set2.contains(ch)) {
        //             System.out.print(ch);
        //             set2.add(ch);
        //         }
        //     }
        // }
    }

    //前k个高频单词

    public List<String> topKFrequent(String[] words, int k) {
        //1. 需要去统计 每个单词出现的次数
        HashMap<String,Integer> map = new HashMap();
        for(String str : words){
            if(!map.containsKey(str)){
                map.put(str,1);
            }else{
                int val = map.get(str);
                map.put(str,val + 1);
            }
        }
        //2. 通过上述代码 我们已经得到了，每个单词出现的次数，存储到了map当中
        // 也就是说，如果看哪个单词出现的频率，接下来要遍历的是map
        //2.1 创建小根堆
        PriorityQueue<Map.Entry<String,Integer>> minHeap = new PriorityQueue<>(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                if(o1.getValue().compareTo(o2.getValue()) == 0) {
                    return o2.getKey().compareTo(o1.getKey());//根据key变成大根堆
                }
                return o1.getValue().compareTo(o2.getValue());
            }
        });
        //3. 遍历map 把每个单词及频率获取到，存放到小根堆当中。以TOPK的问题去解决。
        for (Map.Entry<String, Integer> entry: map.entrySet()){
            if(minHeap.size() < k){
                minHeap.offer(entry);
            }else {
                if(minHeap.peek().getValue().compareTo(entry.getValue()) == 0){
                    if(minHeap.peek().getKey().compareTo(entry.getKey()) > 0){
                        minHeap.poll();
                        minHeap.offer(entry);
                    }
                }else {
                    if(minHeap.peek().getValue().compareTo(entry.getValue()) < 0){
                        minHeap.poll();
                        minHeap.offer(entry);
                    }
                }
            }
        }
        List<String> ret = new ArrayList<>();
        for (int i = 0; i < k; i++){
            Map.Entry<String,Integer> tmp = minHeap.poll();
            ret.add(tmp.getKey());
        }
        Collections.reverse(ret);
        return ret;
    }

    //存在重复元素
    public boolean containsDuplicate(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for(int num : nums){
            if(!set.contains(num)){
                set.add(num);
                continue;
            }
            if(set.contains(num)){
                return true;
            }
        }
        return false;
    }

    //存在重复元素 II

    //复杂链表的复制
    class Node {
        int val;
        Node next;
        Node random;

        public Node(int val) {
            this.val = val;
            this.next = null;
            this.random = null;
        }
    }
    public Node copyRandomList(Node head) {
        HashMap<Node, Node> map = new HashMap<>();
        Node cur = head;
        while (cur != null) {
            Node node = new Node(cur.val);
            map.put(cur, node);
            cur = cur.next;
        }
        cur = head;
        while (cur != null) {
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(head);
    }
}